var code; //在全局 定义验证码

function createCode() {
	code = "";
	var codeLength = 4;//验证码的长度
	var checkCode = document.getElementById("checkCode");
	checkCode.value = "";
	var selectChar = new Array(0,1,2,3,4,5,6,7,8,9);
	for (var i = 0; i < codeLength; i++) {
		var charIndex = Math.floor(Math.random() * 62);
		code += selectChar[charIndex];
	}
	if (code.length != codeLength) {
		createCode();
	}
	checkCode.value = code;
}
function login() {
	var name = document.getElementById("user_id").value;
	var psw = document.getElementById("user_password").value;
	var yzm1 = document.getElementById("checkCode").value.toUpperCase();
	var yzm2 = document.getElementById("authcode").value.toUpperCase();
	if (name == null || name == "") {
		alert('登录名不能为空!');
		return;
	}
	if (psw == null || psw == "") {
		alert('密码不能为空!');
	}
	if (yzm1 != yzm2) {
		alert('验证码输入错误!');
		createCode();
		return;
	}
	$.post("Login!login",
			{
				user_id:name,
				user_password:psw
			},
			function(message){
				var flag = message.returnFlag;//Y N
				if (flag == 'Y') {//登录成功
					window.location.href="./main.jsp";
				}else {
					alert(message.returnMsg);
				}
			}
		);
}
//注销登录
function rollback(){
	loginInfoForm.action="Login!outLogin";
	loginInfoForm.submit();
}
//重新登录
function reloginopen(){
	$("#dlg").dialog('open');
}
function relogin(){
	var user_id = $("#user_id").val();
	var user_password = $("#user_password").val();
	if (user_id == null || user_id == "") {
		$.messager.show({
			title:'提示信息',
			msg:'登录名不能为空!'
		});
		return;
	}
	if (user_password == null || user_password == "") {
		$.messager.show({
			title:'提示信息',
			msg:'密码不能为空!'
		});
		return;
	}
	$.post("Login!login",
		{
			user_id:user_id,
			user_password:user_password
		},
		function(message){
			var flag = message.returnFlag;//Y N
			if (flag == 'Y') {//登录成功
				initinfo();
				$.messager.alert('提示',message.returnMsg,'info');
				$("#dlg").dialog('close');
			}else {
				$.messager.show({
					title:'提示',
					msg:message.returnMsg
				});
			}
		}
	);
}